package com.hncc.dms.controller;

import java.util.List;
import java.util.Map;

import com.hncc.dms.domain.vo.DmsRegistrationVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.dms.domain.DmsRegistration;
import com.hncc.dms.service.IDmsRegistrationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 就诊(门诊)信息Controller
 * 
 * @author ruoyi
 * @date 2020-09-04
 */
@RestController
@RequestMapping("/dms/registration")
@Api(tags = "就诊(门诊)信息接口")
public class DmsRegistrationController extends BaseController
{
    @Resource
    private IDmsRegistrationService dmsRegistrationService;

    /**
     * 查询就诊(门诊)信息列表
     */
    @ApiOperation(value = "条件分页查询就诊(门诊)信息",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('dms:registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsRegistration dmsRegistration)
    {
        startPage();
        List<DmsRegistration> list = dmsRegistrationService.selectDmsRegistrationList(dmsRegistration);
        return getDataTable(list);
    }

    /**
     * 导出就诊(门诊)信息列表
     */
    @PreAuthorize("@ss.hasPermi('dms:registration:export')")
    @Log(title = "就诊(门诊)信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DmsRegistration dmsRegistration)
    {
        List<DmsRegistration> list = dmsRegistrationService.selectDmsRegistrationList(dmsRegistration);
        ExcelUtil<DmsRegistration> util = new ExcelUtil<DmsRegistration>(DmsRegistration.class);
        return util.exportExcel(list, "registration");
    }

    /**
     * 获取就诊(门诊)信息详细信息
     */
    @ApiOperation(value = "根据id获取就诊(门诊)信息详细信息",httpMethod = "GET",
            notes = "根据id查询就诊(门诊)信息")
    @ApiImplicitParam(paramType = "path",name = "id",value = "就诊(门诊)信息id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('dms:registration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dmsRegistrationService.selectDmsRegistrationById(id));
    }

    /**
     * 新增就诊(门诊)信息
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增就诊(门诊)信息")
    @ApiImplicitParam(name = "dmsRegistration", value = "新增就诊(门诊)信息", dataType = "DmsRegistration")
    @PreAuthorize("@ss.hasPermi('dms:registration:add')")
    @Log(title = "就诊(门诊)信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsRegistration dmsRegistration)
    {
        return toAjax(dmsRegistrationService.insertDmsRegistration(dmsRegistration));
    }

    /**
     * 修改就诊(门诊)信息
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改就诊(门诊)信息")
    @ApiImplicitParam(name = "dmsRegistration", value = "修改就诊(门诊)信息", dataType = "DmsRegistration")
    @PreAuthorize("@ss.hasPermi('dms:registration:edit')")
    @Log(title = "就诊(门诊)信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsRegistration dmsRegistration)
    {
        return toAjax(dmsRegistrationService.updateDmsRegistration(dmsRegistration));
    }

    /**
     * 删除就诊(门诊)信息
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除就诊(门诊)信息")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "就诊(门诊)信息id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('dms:registration:remove')")
    @Log(title = "就诊(门诊)信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsRegistrationService.deleteDmsRegistrationByIds(ids));
    }

    /**
     * 根据患者姓名或病历号获取挂号收费信息
     * @param dmsRegistrationVo
     * @return
     */
    @GetMapping("/getByNameOrNo")
    public TableDataInfo getByNameOrMedicalRecordNo(DmsRegistrationVo dmsRegistrationVo){
        startPage();
        List<DmsRegistration> list = dmsRegistrationService.selectByNameOrMedicalRecordNo(dmsRegistrationVo.getName(),dmsRegistrationVo.getMedicalRecordNo());
        return getDataTable(list);
    }

    /**
     * 退号操作
     * @param params
     * @return
     */
    @PutMapping("/returnNo")
    public AjaxResult returnNo(@RequestBody Map<String,Long> params){
        return toAjax(dmsRegistrationService.returnNo(params.get("id"),params.get("registrationId"),params.get("skdId")));
    }
}
